//
//  XJCommunityIwantServeCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/1.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJCommunityIwantServeCell.h"

@interface XJCommunityIwantServeCell()
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) UILabel *leftLabel; //服务名称/联系人称呼 、联系人电话


@end
@implementation XJCommunityIwantServeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 一 init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if(self) {
        [self setupView];
    }
    return self;
}


- (void)setupView {
    
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.leftLabel];
    [self.bgView addSubview:self.rightTF];
}

#pragma mark - 二 lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
    }
    return _bgView;
}

- (UILabel *)leftLabel{
    if (!_leftLabel) {
        _leftLabel = [UILabel new];
    }
    return _leftLabel;
}
- (UITextField *)rightTF {
    if (!_rightTF) {
        _rightTF = [[UITextField alloc] init];
        _rightTF.placeholder = @"请输入";
        [_rightTF addTarget:self action:@selector(textFieldAction:) forControlEvents:(UIControlEventEditingChanged)]; // 输入改变就会触发该方法
    }
    return _rightTF;
}


#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat kLeft = ADAPTWidth(15);
//    CGFloat kLeft = 15;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(kLeft);
        make.top.bottom.equalTo(self.bgView);
        make.width.mas_equalTo(120);
    }];
    [self.rightTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftLabel.mas_right).offset(5);
        make.top.bottom.right.equalTo(self.bgView);
    }];
}

#pragma mark - 四 configure
-  (void)configureLeftLabelStr:(NSString *)leftStr rightTfStr:(NSString *)rightStr {
    self.leftLabel.text = leftStr;
    self.rightTF.text = rightStr;
}

- (void)textFieldAction:(UITextField *)tf {
    
    if (self.serveCellBlock) {
        self.serveCellBlock(tf.text);
    }
}
@end
